# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=kdstatemachineeditor
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-qt5"
pkgver=1.2.8
pkgrel=1
arch=('any')
url="https://github.com/KDAB/KDStateMachineEditor/"
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
pkgdesc="Library for visualizing and editing state charts"
license=('GPL')
depends=(${MINGW_PACKAGE_PREFIX}-graphviz
         ${MINGW_PACKAGE_PREFIX}-qt5-base
         ${MINGW_PACKAGE_PREFIX}-qt5-quickcontrols2
         ${MINGW_PACKAGE_PREFIX}-qt5-remoteobjects
         ${MINGW_PACKAGE_PREFIX}-qt5-scxml
         ${MINGW_PACKAGE_PREFIX}-qt5-xmlpatterns)
makedepends=(${MINGW_PACKAGE_PREFIX}-cmake
             ${MINGW_PACKAGE_PREFIX}-ninja
             ${MINGW_PACKAGE_PREFIX}-extra-cmake-modules
             ${MINGW_PACKAGE_PREFIX}-doxygen
             "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://github.com/KDAB/KDStateMachineEditor/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz
        001-find-graphviz.patch)
noextract=(${_realname}-${pkgver}.tar.gz)
sha256sums=('8676276debd1f8333794aba08d643660f36b698ca4c9711ce0a03c7a84f03e0c'
            '7d6c4e7420c6277352f9b4e01c3b68ebe5b91f292363d59fa8ff2661ce821b8f')
validpgpkeys=(E86C000370B1B9E2A9191AD53DBFB6882C9358FB) # KDAB Products <info@kdab.com>

prepare() {
  [[ -d ${srcdir}/${_realname}-${pkgver} ]] && rm -rf ${srcdir}/${_realname}-${pkgver}
  tar -xf ${srcdir}/${_realname}-${pkgver}.tar.gz -C "${srcdir}" || true

  mkdir -p build-${CARCH}

  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-find-graphviz.patch
}

build() {
  cd build-${CARCH}

  LDFLAGS+=" -L$(cygpath -am ${MINGW_PREFIX}/lib/binutils)"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=;-DECM_MKSPECS_INSTALL_DIR;" \
  ${MINGW_PREFIX}/bin/cmake.exe \
      -G "Ninja" \
      -DCMAKE_BUILD_TYPE=RelWithDebInfo \
      -DCMAKE_INSTALL_OLDINCLUDEDIR=${MINGW_PREFIX}/include \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DECM_MKSPECS_INSTALL_DIR=${MINGW_PREFIX}/share/qt5/mkspecs/modules \
      -DBUILD_QT6=OFF \
      -DBUILD_TESTS=OFF \
      -DGRAPHVIZ_ROOT=${MINGW_PREFIX} \
      ${extra_conf} \
      ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd build-${CARCH}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --build ./ --target install
}
